﻿//(function($){ 
//    $.fn.regionp = function(){
//	   var region = $(this);
//	   var content = "<input id='provinceCombo' name='provinceId' class='mini-combobox' style='width:100px' textField='name' valueField='id' url='/province/listByItem' onvaluechanged='provinceChanged' required='true'>" +
//		"<input id='cityCombo' name='cityId' class='mini-combobox' textField='name' valueField='id'  style='width:100px' onvaluechanged='cityChanged' required='true'>" +
//		"<input id='regionCombo' name='regionId' class='mini-combobox' textField='name' valueField='id' style='width:100px' required='true' onvaluechanged='regionChanged'>";
//	   region.append(content)
//    }
//    
//})(jQuery);
////改变省
//function provinceChanged(){  
//	var provinceCombo = mini.get("provinceCombo"); 
//	var cityCombo = mini.get("cityCombo");
//	var regionCombo = mini.get("regionCombo");
//	var id = provinceCombo.getValue();
//	cityCombo.setValue(""); 
//   var url = "/city/listByItem?provinceId="+id;
//   cityCombo.setUrl(url);
//
//	regionCombo.setValue("");
//   var regionurl = "/region/listByItem?cityId="+id;
//   regionCombo.setUrl(regionurl);
//   
//
//	var itemCombo = mini.get("itemCombo");
//   var itemurl = "/item/getListBypcrId?province_id="+id
//   itemCombo.setUrl(itemurl);  
//   
//   
//}

////改变市
//function cityChanged(){
//	var provinceCombo = mini.get("provinceCombo"); 
//	var cityCombo = mini.get("cityCombo");
//	var regionCombo = mini.get("regionCombo");
//	var province_id=provinceCombo.getValue();
//	var id = cityCombo.getValue();
//	regionCombo.setValue("");
//   var url = "/region/listByItem?cityId="+id;
//   regionCombo.setUrl(url);
//   
//
//	var itemCombo = mini.get("itemCombo");
//   var itemurl = "/item/getListBypcrId?province_id="+province_id+"&city_id="+id;
//   itemCombo.setUrl(itemurl);  
//}

//改变区
function regionChanged(){
	var provinceCombo = mini.get("provinceCombo"); 
	var cityCombo = mini.get("cityCombo");
	var regionCombo = mini.get("regionCombo");
	var province_id=provinceCombo.getValue();
	var city_id = cityCombo.getValue();
	var region_id = regionCombo.getValue();
   

	var itemCombo = mini.get("itemCombo");
    var itemurl = "/item/getListBypcrId?province_id="+province_id+"&city_id="+city_id+"&region_id="+region_id;
    itemCombo.setUrl(itemurl);  
}


//通过项目id获取期区 
 function  getPeriodByitemId(){
	 var itemCombo = mini.get("itemCombo");
	 var itemId = itemCombo.getValue();
	
	var periodId = mini.get("periodId");
    var periodurl = "/periodInfo/listByItemChecked?itemId="+itemId;
    periodId.setUrl(periodurl);  
	 
 } 
 
 /**
  * 根据部门查询人员
  */
 function getManagerByDepartment(){
	 var departmentCombo = mini.get("departmentCombo");
	 var departmentId = departmentCombo.getValue();
	 var managerCombo = mini.get("mangerCombo");
	 var url = "/org/employees?officeId="+departmentId;
	 managerCombo.setUrl(url);
 }
 

//关闭窗口
    function CloseWindow(action) {
        if (window.CloseOwnerWindow) return window.CloseOwnerWindow(action);
        else window.close();
    }
//////////////////////////////////////////
    function updateError(e) {
//    	验证非空
        var id_error = e.sender.name + "_error";
//        var el = document.getElementById(id);
    	var el = '<div id='+id_error+'  class="errorText">'+e.errorText+'</div>';
    	var input_el = $("input[name='"+e.sender.name+"']").parent().parent();//页面追加div提示数据框
    	if ($("#"+id_error).length==0) {
    		$(el).insertAfter(input_el);
    	}
    	if(e.isValid){
    		$("#"+id_error).html("");
    		$(input_el).next().remove("div");
    	}
    }
//    验证非空
    function onNullValidation(e) {                  
        updateError(e);
    }
    function upChoseError(e) {
//    	验证选择
        var id_error = e.sender.name + "_error";
//        var el = document.getElementById(id);
    	var el = '<div id='+id_error+'  class="errorText">'+e.errorText+'</div>';
    	var input_el = $("input[name="+e.sender.name+"]").parent();//页面追加div提示数据框
    	if ($("#"+id_error).length==0) {
    		$(el).insertAfter(input_el);
    	}
    	if(e.isValid){
    		$("#"+id_error).html("");
    		$(input_el).next().remove("div");
    	}
    }
    function onChoseValidation(e) {                  
    	upChoseError(e);
    }
//  验证联系方式
    function onPhonevalidation(e){
    	var id_error = e.sender.name + "_error";
//        var el = document.getElementById(id);
    	if(e.value==""){
    		e.errorText = "请输入";
            e.isValid = false;
    	}else if (isPhone(e.value) == false) {
            e.errorText = "格式错误";
            e.isValid = false;
        }
    	var el = '<div id='+id_error+'  class="errorText">'+e.errorText+'</div>';
    	var input_el = $("input[name="+e.sender.name+"]").parent().parent();//页面追加div提示数据框
    	$("#"+id_error).html(e.errorText);
    	if ($("#"+id_error).length==0) {
    		$(el).insertAfter(input_el);
    	}
    	if (e.isValid) {
    		$("#"+id_error).html("");
    		$(input_el).next().remove("div");
    		
        }
    }
    /* 是否联系方式*/
    function isPhone(v) {
        var re =  /^1\d{10}$/;
        if (re.test(v)) return true;
        return false;
    }
//    验证金额或数字
    function onSumvalidation(e){
    	console.log(e)
    	var id_error = e.sender.name + "_error";
    	console.log(isSum(e.value))
    	if(e.value==""){
    		e.errorText = "请输入";
            e.isValid = false;
    	}else if (isSum(e.value) == false) {
            e.errorText = "请输数字";
            e.isValid = false;
        }
    	var el = '<div id='+id_error+'  class="errorText">'+e.errorText+'</div>';
    	var input_el = $("input[name="+e.sender.name+"]").parent().parent();//页面追加div提示数据框
    	$("#"+id_error).html(e.errorText);
    	if ($("#"+id_error).length==0) {
    		$(el).insertAfter(input_el);
    	}
    	if (e.isValid) {
    		$("#"+id_error).html("");
    		$(input_el).next().remove("div");
    		
        }
    }
    /* 是否金额 */
    function isSum(v) {
    	console.log(v)
        var re = /^[1-9]\d*$/;
        if (re.test(v)) return true;
        return false;
    }
    
//  验证英文和数字 
 function onEnglishAndNumberValidation(e) {
	 console.log(e)
 	var id_error = e.sender.name + "_error";
 	console.log(isSum(e.value))
 	if(e.value==""){
 		e.errorText = "请输入";
         e.isValid = false;
 	}else if (isEnglishAndNumber(e.value) == false) {
         e.errorText = "输入英文+数字";
         e.isValid = false;
     }
 	var el = '<div id='+id_error+'  class="errorText">'+e.errorText+'</div>';
 	var input_el = $("input[name="+e.sender.name+"]").parent().parent();//页面追加div提示数据框
 	$("#"+id_error).html(e.errorText);
 	if ($("#"+id_error).length==0) {
 		$(el).insertAfter(input_el);
 	}
 	if (e.isValid) {
 		$("#"+id_error).html("");
 		$(input_el).next().remove("div");
 		
     }
}
 /* 是否英文+数字 */
 function isEnglishAndNumber(v) {
     
     var re = new RegExp("^[0-9a-zA-Z\_]+$");
     if (re.test(v)) return true;
     return false;
 }
    /**
     * 判断开始日期是否大于结束日期
     * @param {} value
     * @param {} param
     * @return {Boolean}
     */
//    日期格式化
 function ondayRenderer(e) {
		if (e.value) {
			var value = new Date(e.value);
			if (value) {
				return mini.formatDate(value, 'yyyy-MM-dd')
			}
		}else{
			return "";
		}
	}

//    弹出提示框
function loading(message) {
    mini.mask({
        el: document.body,
        cls: 'mini-mask-loading',
        html: message
    });

}
//    取消遮罩
function unmask(){
    setTimeout(function () {
        mini.unmask(document.body);
    }, 1000);
}